/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package application;
import java.io.*;
import java.net.*;


/**
 *
 * @author suvam
 */
class myThread extends Thread
{

    Socket threadSoc;

    myThread(Socket inSoc)
    {
        threadSoc = inSoc;
    }

    public void run()
    {
        try
        {

            PrintWriter out = new PrintWriter(threadSoc.getOutputStream(), true);
           
            String outputLine;
             BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));


             InputDataThread th=new InputDataThread(threadSoc);
             th.start();

            while (true)//(inputLine = in.readLine()) != null)
            {
                


                outputLine = stdIn.readLine();
                if(!th.isAlive())
                    break;
                if (outputLine != null)
                {
                    System.out.println("Me : " + outputLine);
                out.println(outputLine);
                }
                
                if (outputLine.equals("Bye."))
                {
                    if(th.isAlive())
                        th.stop();
                      break;
                }
            }


            out.close();
           
            stdIn.close();
        }


        catch (Exception e)
        {
            System.out.println("Whoops! " +
            e.toString());
        }

        try
        {
            threadSoc.close();
        }
        catch (Exception e)
        {
            System.out.println("Oh no! " +
            e.toString());
        }
    }
}
